<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<table class="display" id="example">
    <thead>
    <tr>
        <th>选择</th>
        <th>部门</th>
        <th>岗位</th>
        <th>实际在职人数</th>
        <th>考核指标设定状态</th>
        <th width="80px">操作</th>
    </tr>
    </thead>
    <tbody>
    <s:if test="#request.examBaseConfigPojos==null || #request.examBaseConfigPojos.size() <= 0">
        <tr class="gradeA"> <td colspan="8">暂无数据</td> </tr>
    </s:if>
    <s:else>
        <s:iterator value="#request.examBaseConfigPojos" var="config" status="sta">
            <s:if test="#sta.even"> <tr class="gradeA"> </s:if> <s:else> <tr class="gradeC"> </s:else>
            <td><input type="checkbox" alt="${config.dutyName}" name="check_config_o${organizationId}" value="${config.id}" ${config.id == null ? "disabled='true'" : ""} /></td>
            <td>${config.organizeName}</td>
            <td>${config.dutyName}</td>
            <td>${config.actualNumber}</td>
            <s:if test="#request.config.id == null">
            <td>尚未设定</td>
            <td><a class="button" style="color: #777777"><span style="background:url(${ctx}/images/img/page_edit.png)" class="icon">&nbsp;</span>配置</a></td>
            </s:if>
            <s:else>
            <td><div id="progress3" class="progress"><span style="width: ${config.percentageQualitative}%;"><b>${config.percentageQualitative}%</b></span></div></td>
            <td>
                <a class="button" href="#authority/audit_config_set.xhtml?auditType=audit_exam_qual_target&tid=${config.id}&organizationId=${organizationId}&tn=${config.dutyName}"><span style="background:url(${ctx}/images/img/page_edit.png)" class="icon">&nbsp;</span>配置</a>
            </td>
            </s:else>
            </tr>
        </s:iterator>
    </s:else>
    </tbody>
</table>

<p><%@ include file="/WEB-INF/pages/common/main_orgtab_pager.jsp"%></p>

<script type="text/javascript">
    function batchOperator(type){
        var config_ids = new Array();
        var tns = new Array();
        var items = $("input[type='checkbox'][name='check_config_o${organizationId}']").each(function() {
            if($(this).attr("checked")){
                var configId = $(this).val();
                if(configId > 0){
                    config_ids.push(configId);
                    tns.push($(this).attr("alt"));
                }
            }
        });
        if(config_ids.length == 0){
            alert("没有选择任何数据项");
            return;
        }
        if(type =="config"){
            if(config_ids.length == 1){
                window.location.href="#authority/audit_config_set.xhtml?auditType=audit_exam_qual_target&organizationId=${organizationId}&tid="+config_ids[0]+"&tn=" + tns.join(",");
                return;
            }

            var batchIds = config_ids.join(",");
            if(!confirm("批量配置将会清除所选记录的配置项，确定要批量配置吗?")){
                return;
            }
            $.getJSON("${ctx}/ajax/audit-config-batch-reset.xhtml", {"auditing.auditingNo":"audit_exam_qual_target", "auditing.organization.id":${organizationId}, "batchIds":batchIds}, function(res) {
                if(res){
                    window.location.href="#authority/audit_config_set.xhtml?auditType=audit_exam_qual_target&organizationId=${organizationId}&batchIds="+batchIds+"&batchType="+type+"&tid="+config_ids[0]+"&tn=" + tns.join(",");
                }else{
                    alert("清除配置失败,部分审核配置可能在使用中");
                }
            });

        }else if(type == "remove"){
            resetConfigs(config_ids.join(","));
        }

    }

    function resetConfigs(configIds){
        if(!confirm("确定要重置该审核配置吗?")){
            return;
        }
        $.getJSON("${ctx}/ajax/audit-config-batch-reset.xhtml", {"auditing.auditingNo":"audit_exam_qual_target", "auditing.organization.id":${organizationId}, "batchIds":configIds}, function(res) {
            if(res){
                alert("重置成功");
            }else{
                alert("重置失败,该审核配置可能在使用中");
            }
        });
    }
</script>